package user_assets_pix

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserPixWalletInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 用户Pix钱包信息 - 查询
func NewUserPixWalletInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserPixWalletInfoLogic {
	return &UserPixWalletInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserPixWalletInfoLogic) UserPixWalletInfo(req *types.UserPixWalletsInfoRequest) (resp *types.UserPixWalletsInfoResponse, err error) {
	info, err := l.svcCtx.AssetsRpc.UserChannel.UserPixWalletsInfo(l.ctx, &rpc.UserPixWalletsInfoRequest{
		UserId:     req.UserID,
		Account:    req.Account,
		Cpf:        req.CPF,
		Username:   req.Username,
		WalletType: req.WalletType,
	})
	var dataList []*types.UserPixWalletsInfo

	if err != nil {
		return &types.UserPixWalletsInfoResponse{
			UserPixWalletsInfoList: dataList,
		}, err
	}
	for i := 0; i < len(info.UserPixWalletsInfoList); i++ {
		item := &types.UserPixWalletsInfo{
			Id:     info.UserPixWalletsInfoList[i].Id,
			UserId: info.UserPixWalletsInfoList[i].UserId,
			// WalletTypeName: emun.GetUserPixWalletNameByType(info.UserPixWalletsInfoList[i].WalletType),
			Username: info.UserPixWalletsInfoList[i].Username,
			CPF:      info.UserPixWalletsInfoList[i].Cpf,
			Account:  info.UserPixWalletsInfoList[i].Account,
		}

		dataList = append(dataList, item)
	}

	return &types.UserPixWalletsInfoResponse{
		UserPixWalletsInfoList: dataList,
	}, nil
}
